package com.xjl.user.dbArchiving.archiving.factory;

import com.xjl.user.dbArchiving.archiving.BackUpDatahandler;
import com.xjl.user.dbArchiving.enums.BackUpDataSceneEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class BackUpDataFactory implements InitializingBean {

    @Resource
    List<BackUpDatahandler> backUpDatahandlerList;

    private static Map<BackUpDataSceneEnum,BackUpDatahandler> handlerMap = new HashMap<>();

    public BackUpDatahandler getHandlerByCode(String code){
        BackUpDataSceneEnum backUpDataSceneEnum = BackUpDataSceneEnum.getByCode(code);
        return handlerMap.get(backUpDataSceneEnum);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        for(BackUpDatahandler handler:backUpDatahandlerList){
            handlerMap.put(handler.getScene(),handler);
        }
    }
}
